﻿Imports Spring.Transaction.Interceptor
Imports Spring.Transaction

<Serializable()> _
Public Class ErrorLog
    Inherits BaseDominio

#Region "Propriedades"

    Private _id As Long
    Public Overridable Property Id() As Long
        Get
            Return _id
        End Get
        Set(ByVal value As Long)
            _id = value
        End Set
    End Property

    Private _usuario As String
    Public Overridable Property Usuario() As String
        Get
            Return _usuario
        End Get
        Set(ByVal value As String)
            _usuario = value
        End Set
    End Property

    Private _pagina As String
    Public Overridable Property Pagina() As String
        Get
            Return _pagina
        End Get
        Set(ByVal value As String)
            _pagina = value
        End Set
    End Property

    Private _message As String
    Public Overridable Property Message() As String
        Get
            Return _message
        End Get
        Set(ByVal value As String)
            _message = value
        End Set
    End Property

    Private _source As String
    Public Overridable Property Source() As String
        Get
            Return _source
        End Get
        Set(ByVal value As String)
            _source = value
        End Set
    End Property

    Private _classe As String
    Public Overridable Property Classe() As String
        Get
            Return _classe
        End Get
        Set(ByVal value As String)
            _classe = value
        End Set
    End Property

    Private _metodo As String
    Public Overridable Property Metodo() As String
        Get
            Return _metodo
        End Get
        Set(ByVal value As String)
            _metodo = value
        End Set
    End Property

    Private _stackTrace As String
    Public Overridable Property StackTrace() As String
        Get
            Return _stackTrace
        End Get
        Set(ByVal value As String)
            _stackTrace = value
        End Set
    End Property

    Private _innerStackTrace As String
    Public Overridable Property InnerStackTrace() As String
        Get
            Return _innerStackTrace
        End Get
        Set(ByVal value As String)
            _innerStackTrace = value
        End Set
    End Property

    Private _REMOTE_ADDR As String
    ''' <summary>
    ''' Request.ServerVariables("REMOTE_ADDR")
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overridable Property REMOTE_ADDR() As String
        Get
            Return _REMOTE_ADDR
        End Get
        Set(ByVal value As String)
            _REMOTE_ADDR = value
        End Set
    End Property

    Private _HTTP_REFERER As String
    ''' <summary>
    ''' Request.ServerVariables("REMOTE_ADDR")
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overridable Property HTTP_REFERER() As String
        Get
            Return _HTTP_REFERER
        End Get
        Set(ByVal value As String)
            _HTTP_REFERER = value
        End Set
    End Property

    Private _computerName As String
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overridable Property ComputerName() As String
        Get
            Return _computerName
        End Get
        Set(ByVal value As String)
            _computerName = value
        End Set
    End Property

#End Region

#Region "Negocio"

    Public Sub New()

    End Sub

    Public Sub New(ByVal _excecao As Exception)

        Me.InicializaClasse(_excecao, String.Empty, String.Empty)

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="_excecao"></param>
    ''' <param name="_sessionUser">String da Session("_user")</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal _excecao As Exception, _
                   ByVal _sessionUser As String)

        Me.InicializaClasse(_excecao, _sessionUser, String.Empty)

    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="_excecao"></param>
    ''' <param name="_sessionUser">String da Session("_user")</param>
    ''' <param name="_pagina"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal _excecao As Exception, _
                   ByVal _sessionUser As String, _
                   ByVal _pagina As String)

        Me.InicializaClasse(_excecao, _sessionUser, _pagina)

    End Sub

    Public Sub New(ByVal _mensagem As String, ByVal _source As String)

        Dim _excecao As New Exception(_mensagem)
        _excecao.Source = _source
        Me.InicializaClasse(_excecao, "NOTHING", "NOTHING")

    End Sub

    Private Sub InicializaClasse(ByVal _excecao As Exception, _
                   ByVal _sessionUser As String, _
                   ByVal _pagina As String)

        With _excecao
            Me.Message = .Message
            Me.Source = _excecao.Source
            Me.StackTrace = _excecao.StackTrace
            If .InnerException IsNot Nothing Then
                Me.InnerStackTrace = .InnerException.Message & " : " & .InnerException.StackTrace
            End If
            If _excecao.TargetSite IsNot Nothing Then
                Me.Metodo = _excecao.TargetSite.Name
                If _excecao.TargetSite.ReflectedType IsNot Nothing Then
                    Me.Classe = _excecao.TargetSite.ReflectedType.FullName
                End If
            End If
        End With

        Me.Usuario = _sessionUser
        Me.Pagina = _pagina

    End Sub

    <Transaction(TransactionPropagation.Required)> _
    Public Overridable Sub Salvar()

        MyBase.ErrorLogDao.Salvar(Me)

    End Sub

#End Region

End Class
